<?php
namespace core;
class stupboy {
	public static $classMap = array();
	public $assign = array();
    public $smarty;
    public function __construct(){
        $this->smarty = new \smarty();
        $this->smarty->template_dir = APP.'/views/';
		$this->smarty->compile_dir = APP.'/templates_c/';
		$this->smarty->config_dir = 'app/configs/';
		$this->smarty->cache_dir = 'app/cache/';
    }
	public static function run(){
		\core\lib\log::init();
		$route = new \core\lib\route();
		$ctrlClass = $route->ctrl;
		$action = $route->action;
		$ctrlFile = APP.'/ctrl/'.$ctrlClass.'Ctrl.php';
		if(is_file($ctrlFile)){
			include $ctrlFile;
			$ctrlName = '\\'.MODULE.'\ctrl\\'.$ctrlClass.'Ctrl';
			$ctrl = new $ctrlName();
			$ctrl->$action();
			\core\lib\log::log('ctrl:'.$ctrlName,'server');
		}else{
            // echo $ctrlClass;exit();
			throw new \Exception('can not find'.$ctrlClass);
		}
	}
	public static function load($class){
		// 自动加载类库
		// new \core\route();
		// $class = '\core\route';
		// STUPBOY .'/core/route.php';
		if(isset($classMap[$class])){
			return true;
		}else{
			$class = str_replace('\\','/',$class);
			$file = STUPBOY.'/'.$class.'.php';
			if(is_file($file)){
				include $file;
				self::$classMap[$class] = $class;
			}else{
				return true;
			}
		}
		
	}
	public function assign($name,$value)
	{
		// $this->assign[$name] = $value;
        $this->smarty->assign($name,$value);
	}
	public function display($file)
	{
		// $file = APP.'/views/'.$file;
		// if(is_file($file)){
			// extract($this->assign);
			// include $file;
		// }
       $this->smarty->display('index.html');
	}
}